#!/usr/env python3
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

def point_by_point_comparison(xe, ye, type, x0=0, y0=0):
    if(type == "linear"):
        x0 = 0
        y0 = 0
    n = xe + ye + x0 + y0 # 步长默认1
    result = np.empty([n+1,2])
    F = 0
    xi = x0
    yi = y0
    i = 0
    result[i] = [xi, yi]
    i = i + 1

    if(type == "linear"):
        #F = y*xe - x*ye
        while(n > 0):
            if(F >= 0):
                # to X axie
                F = F - ye
                xi = xi + 1
            elif(F < 0):
                # to Y axie
                F = F + xe
                yi = yi + 1

            result[i] = [xi, yi]
            n = n - 1
            i = i + 1
    
    elif(type == "arc"):
        if(x0 == 0 and y0 == 0):
            return False
        #F = (x*x + y*y) - (x0*x0 + y0*y0)
        while(n > 0):
            if(F >= 0):
                # to -X axie
                F = F - 2 * xi + 1
                xi = xi - 1
            elif(F < 0):
                # to Y axie
                F = F + 2 * yi + 1
                yi = yi + 1

            result[i] = [xi, yi]
            n = n - 1
            i = i + 1
    else:
        return False

    return True, result


if __name__ == "__main__":
    # xe = 12
    # ye = 5
    # ref, result = point_by_point_comparison(xe, ye, "linear")
    
    # plt.plot(result[:, 0], result[:, 1])
    # plt.plot(np.array([0, xe]), np.array([0, ye]))
    # plt.show()


    r = 12
    xe = 0
    ye = r
    x0 = r
    y0 = 0

    ref, result = point_by_point_comparison(xe, ye, "arc", x0=x0, y0=y0)
    figure, axes = plt.subplots()
    draw_circle = plt.Circle((0, 0), r, fill=False)
    axes.set_aspect(1)
    axes.add_artist(draw_circle)
    plt.plot(result[:, 0], result[:, 1])
    plt.show()
